<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
FlyUI Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="genefinder.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>genefinder.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		This script defines a widget for finding Drosophila melanogaster genes via FlyBase.
 <BR/><BR/><B>Version: </B>$Revision:539 $ on $Date: 2008-08-13 16:09:30 +0100 (Wed, 13 Aug 2008) $ by $Author: aliman $
 <BR/><BR/><B>Requires:</B><UL>- YAHOO.log<BR/>- YAHOO.lang.JSON<BR/>- YAHOO.util.Dom<BR/>- YAHOO.util.Connect<BR/>- YAHOO.util.CustomEvent<BR/>- <a href="../../flyui/util.html#">flyui.util</a><BR/>- <a href="../../flyui/flybase.html#">TODO license terms</a></UL><B>Author:</B> <a href="http://purl.org/net/aliman">Alistair Miles</a>
 <BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/genefinder/Controller.html">flyui.genefinder.Controller</a></b></td>
    <td>Controller class for the flyui.genefinder widget.</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/genefinder/DefaultRenderer.html">flyui.genefinder.DefaultRenderer</a></b></td>
    <td>A default renderer for the GeneFinder Widget.</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/genefinder/SelectionOutOfBounds.html">flyui.genefinder.SelectionOutOfBounds</a></b></td>
    <td>An exception thrown if selection index is out of bounds.</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/genefinder/UserEventHandler.html">flyui.genefinder.UserEventHandler</a></b></td>
    <td>Handles user events (clicks etc.) for the genefinder widget.</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/genefinder/Widget.html">flyui.genefinder.Widget</a></b></td>
    <td>A widget for finding and displaying D.</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 * <span class="attrib">@fileoverview</span>
 * This script defines a widget for finding Drosophila melanogaster genes via FlyBase.
 * <span class="attrib">@author</span> &lt;a href="http://purl.org/net/aliman"&gt;Alistair Miles&lt;/a&gt;
 * <span class="attrib">@version</span> $Revision:539 $ on $Date: 2008-08-13 16:09:30 +0100 (Wed, 13 Aug 2008) $ by $Author: aliman $
 * <span class="attrib">@requires</span> YAHOO.log
 * <span class="attrib">@requires</span> YAHOO.lang.JSON
 * <span class="attrib">@requires</span> YAHOO.util.Dom
 * <span class="attrib">@requires</span> YAHOO.util.Connect
 * <span class="attrib">@requires</span> YAHOO.util.CustomEvent
 * <span class="attrib">@requires</span> flyui.util
 * <span class="attrib">@requires</span> flyui.flybase
 * TODO license terms
 */</span>
 
 
<span class="comment">// create a namespace if not already defined</span>
flyui.namespace(<span class="literal">"flyui.genefinder"</span>);

<span class="comment">/*
 * ----------------------------------------------------------------
 *                             WIDGET
 * ----------------------------------------------------------------
 */</span>


<span class="comment">/** 
 * Create a new widget instance.
 * <span class="attrib">@class</span>
 * A widget for finding and displaying D. melanogaster genes from FlyBase.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {flyui.flybase.Service} service the service to use to retrieve data from
 * <span class="attrib">@param</span> {Object} renderer the renderer to use with this widget instance (see also flyui.genefinder.DefaultRenderer)
 */</span>
flyui.genefinder.Widget = <span class="reserved">function</span>( service, renderer ) {
	
	<span class="comment">// do initialisation</span>
	<span class="reserved">this</span>._Widget(service, renderer);
	
};

<span class="comment">/** <span class="attrib">@private</span> */</span>
flyui.genefinder.Widget.<span class="reserved">prototype</span>._controller = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 * <span class="attrib">@type</span> flyui.mvcutils.GenericModel2
 */</span> 
flyui.genefinder.Widget.<span class="reserved">prototype</span>._model = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 */</span>
flyui.genefinder.Widget.<span class="reserved">prototype</span>._renderer = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 */</span>
flyui.genefinder.Widget.<span class="reserved">prototype</span>._service = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 */</span>
flyui.genefinder.Widget.<span class="reserved">prototype</span>._geneSelectedEvent = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 */</span>
flyui.genefinder.Widget.<span class="reserved">prototype</span>._genesFoundEvent = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 * TODO doc me
 */</span>
flyui.genefinder.Widget.<span class="reserved">prototype</span>._Widget = <span class="reserved">function</span>(service, renderer) {
	var _context = <span class="literal">"flyui.genefinder.Widget.prototype._Widget"</span>;
	try {
        
        <span class="reserved">this</span>._service = service;
        <span class="reserved">this</span>._renderer = renderer;
        
        <span class="comment">// create events</span>
        <span class="reserved">this</span>._geneSelectedEvent = new YAHOO.util.CustomEvent(<span class="literal">"GENESELECTED"</span>, <span class="reserved">this</span>);
        <span class="reserved">this</span>._genesFoundEvent = new YAHOO.util.CustomEvent(<span class="literal">"GENESFOUND"</span>, <span class="reserved">this</span>);
    
        <span class="comment">// create a model</span>
        <span class="reserved">this</span>._model = new flyui.mvcutils.GenericModel2();
        <span class="reserved">this</span>._model.setDefinition(flyui.genefinder.modelDefinition);
        
        <span class="comment">// instantiate the controller</span>
        <span class="reserved">this</span>._controller = new flyui.genefinder.Controller(<span class="reserved">this</span>._model, service, <span class="reserved">this</span>);
        
        <span class="comment">// connect the renderer to the model</span>
        <span class="reserved">this</span>._renderer.connect(<span class="reserved">this</span>._model);
        
        <span class="comment">// instantiate a user event handler and pass to renderer</span>
        <span class="reserved">this</span>._renderer.setUserEventHandler(new flyui.genefinder.UserEventHandler(<span class="reserved">this</span>._controller));
        	    
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }    
};


<span class="comment">/**
 * Subscribe to a custom event.
 * <span class="attrib">@param</span> {String} type the type of the event
 * <span class="attrib">@param</span> {Function} listener the callback function
 * <span class="attrib">@param</span> {Object} obj a custom object, passed back to the callback function 
 */</span>
flyui.genefinder.Widget.<span class="reserved">prototype</span>.subscribe = <span class="reserved">function</span>(type, listener, obj) {
    var _context = <span class="literal">"flyui.genefinder.Widget.prototype.subscribe"</span>;
    try {
        <span class="reserved">if</span> (type == <span class="literal">"GENESELECTED"</span>) {
            <span class="reserved">this</span>._geneSelectedEvent.subscribe(listener, obj);
        }
        <span class="reserved">else</span> <span class="reserved">if</span> (type == <span class="literal">"GENESFOUND"</span>) {
            <span class="reserved">this</span>._genesFoundEvent.subscribe(listener, obj);
        }
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }    
};


<span class="comment">/**
 * Find Drosophila genes by any gene name or identifier.
 * <span class="attrib">@param</span> {String} anyName the name or identifier to search by
 * <span class="attrib">@param</span> {Boolean} caseSensitive if true, search is case sensitive
 */</span>
flyui.genefinder.Widget.<span class="reserved">prototype</span>.findGenesByAnyName = <span class="reserved">function</span>( anyName, caseSensitive ) {
    var _context = <span class="literal">"flyui.genefinder.Widget.prototype.findGenesByAnyName"</span>;
    try {
        flyui.debug(<span class="literal">"pass through to controller"</span>, _context);
        <span class="reserved">this</span>._controller.findGenesByAnyName(anyName, caseSensitive);
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }    
};


<span class="comment">/**
 * Set the selection index, where more than one genes are available.
 * <span class="attrib">@param</span> {Number} index the new selection index
 */</span>
flyui.genefinder.Widget.<span class="reserved">prototype</span>.setSelectionIndex = <span class="reserved">function</span>( index ) {
    var _context = <span class="literal">"flyui.genefinder.Widget.prototype.setSelectionIndex"</span>;
    try {
        flyui.debug(<span class="literal">"pass through to controller"</span>, _context);
        <span class="reserved">this</span>._controller.setSelectionIndex(index);
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }    
};

<span class="comment">/**
 * Create a new user event handler for the GeneFinder widget.
 * <span class="attrib">@class</span>
 * Handles user events (clicks etc.) for the genefinder widget.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {flyui.genefinder.Controller} controller the widget's controller
 */</span>
flyui.genefinder.UserEventHandler = <span class="reserved">function</span>( controller ) {

    <span class="comment">/**
     * <span class="attrib">@private</span>
     * Handle a mouse click on a result.
     * <span class="attrib">@param</span> event the browser event
     * <span class="attrib">@param</span> {Number} index the index of the result clicked
     */</span>
	<span class="reserved">this</span>._onResultClicked = <span class="reserved">function</span>( event, index ) {
	    var _context = <span class="literal">"flyui.genefinder.UserEventHandler this._onResultClicked"</span>;
	    try {
            flyui.info(<span class="literal">"received click event, call the controller to set selection: "</span>+index, _context); 
            controller.setSelectionIndex(index);	        
        } catch (e) {
            flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
            throw new flyui.UnexpectedException(_context, e);
        }    
	};	
	
};





<span class="comment">/** 
 * Create a new controller instance.
 * <span class="attrib">@class</span>
 * Controller class for the flyui.genefinder widget.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {flyui.mvcutils.GenericModel2} model the model to use to store data
 * <span class="attrib">@param</span> {flyui.flybase.Service} service the service to use to retrieve data from
 * <span class="attrib">@param</span> {flyui.genefinder.Widget} widget the widget for which this is the controller
 */</span>
flyui.genefinder.Controller = <span class="reserved">function</span>( model, service, widget ) {
	
	var that = <span class="reserved">this</span>;
	
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._model = model;

	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._service = service;

	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._parent = widget;
	
	
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 * Success case callback for the findGenesByAnyName operation.
	 * <span class="attrib">@param</span> {Array&lt;flyui.flybase.Gene&gt;} genes the results of the operation 
	 */</span>
	<span class="reserved">this</span>._findGenesByAnyNameSuccess = <span class="reserved">function</span>( genes ) {
	    var _context = <span class="literal">"flyui.genefinder.Controller this._findGenesByAnyNameSuccess"</span>;
        try {
            
            flyui.info(<span class="literal">"request success"</span>, _context);
            
            <span class="comment">// set the results</span>
            that._model.set(<span class="literal">"RESULTS"</span>, genes);
            
            <span class="comment">// set model state</span>
            that._model.set(<span class="literal">"STATE"</span>, <span class="literal">"READY"</span>);
            
            <span class="comment">// fire event</span>
            flyui.info(<span class="literal">"firing GENESFOUND event"</span>, _context);
            var _event = that._parent._genesFoundEvent;
    <span class="comment">//          flyui.debug("event: "+event, _context);</span>
            _event.fire(genes);
    
            <span class="comment">// auto-select if only one result</span>
            <span class="reserved">if</span> (genes.length == 1) {
                that.setSelectionIndex(0);
            }
            
        } catch (e) {
            flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
            throw new flyui.UnexpectedException(_context, e);
        }    
	};
	
	
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 * Failure case callback for the findGenesByAnyName operation.
	 * <span class="attrib">@param</span> response the HTTP response object (YUI)
	 */</span>
	<span class="reserved">this</span>._findGenesByAnyNameFailure = <span class="reserved">function</span>( response ) {
	    var _context = <span class="literal">"flyui.genefinder.Controller this._findGenesByAnyNameFailure"</span>;
		try {
            flyui.err(<span class="literal">"request failed, status "</span>+response.status+<span class="literal">" "</span>+response.statusText, _context);
            
            <span class="comment">// set the error message</span>
            var msg = <span class="literal">"There was an error retrieving data from FlyBase, see the logs for more info. The server may be busy or down, please try again later. If this message persists, please contact the Image Bioinformatics Research Group at bioimage@mail.ontonet.org."</span>;        
            that._model.set(<span class="literal">"ERRORMESSAGE"</span>, msg);
    
            <span class="comment">// set the state</span>
            that._model.set(<span class="literal">"STATE"</span>, <span class="literal">"SERVERERROR"</span>);        
        } catch (e) {
            flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
            throw new flyui.UnexpectedException(_context, e);
        }    
	};
	
};


<span class="comment">/**
 * Find D. melanogaster genes by any name (including symbols, flybase IDs, synonyms).
 * <span class="attrib">@param</span> {String} anyName any name, symbol or synonym
 * <span class="attrib">@param</span> {Boolean} caseSensitive
 */</span>
flyui.genefinder.Controller.<span class="reserved">prototype</span>.findGenesByAnyName = <span class="reserved">function</span>( anyName, caseSensitive ) {
    var _context = <span class="literal">"flyui.genefinder.Controller.prototype.findGenesByAnyName"</span>;
    try {
        flyui.info(<span class="literal">"findGenesByAnyName: "</span>+anyName, _context);
        flyui.debug(<span class="literal">"pass through to private method"</span>, _context);
        <span class="reserved">this</span>._findGenesByAnyName(anyName, <span class="reserved">this</span>._findGenesByAnyNameSuccess, <span class="reserved">this</span>._findGenesByAnyNameFailure, caseSensitive);
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }    
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Implementation of findGenesByAnyName, allowing insertion of custom callbacks for testing.
 * <span class="attrib">@param</span> {String} anyName any name, symbol or synonym
 * <span class="attrib">@param</span> {Function} success callback
 * <span class="attrib">@param</span> {Function} failure callback
 * <span class="attrib">@param</span> {Boolean} caseSensitive
 */</span>
flyui.genefinder.Controller.<span class="reserved">prototype</span>._findGenesByAnyName = <span class="reserved">function</span>( anyName, success, failure, caseSensitive ) {
    var _context = <span class="literal">"flyui.genefinder.Controller.prototype._findGenesByAnyName"</span>;
    try {
        flyui.debug(<span class="literal">"_findGenesByAnyName: "</span>+anyName, _context);
        
        flyui.debug(<span class="literal">"set state pending"</span>, _context);
        <span class="reserved">this</span>._model.set(<span class="literal">"STATE"</span>, <span class="literal">"PENDING"</span>);
        
        flyui.debug(<span class="literal">"set model property query"</span>, _context);
        <span class="reserved">this</span>._model.set(<span class="literal">"QUERY"</span>, anyName);
        
        flyui.debug(<span class="literal">"kick off request"</span>, _context);
        <span class="reserved">if</span> (caseSensitive) {
            <span class="reserved">this</span>._service.findGenesByAnyName(anyName, success, failure);
        } <span class="reserved">else</span> {
            <span class="reserved">this</span>._service.findGenesByAnyNameCaseInsensitive(anyName, success, failure);
        }
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }    
};


<span class="comment">/**
 * Set the index of the selected result.
 * <span class="attrib">@param</span> {Number} index the new selection index
 * <span class="attrib">@throws</span> flyui.genefinder.SelectionOutOfBounds if selection index is not applicable to current results
 */</span>
flyui.genefinder.Controller.<span class="reserved">prototype</span>.setSelectionIndex = <span class="reserved">function</span>( index ) {
    var _context = <span class="literal">"flyui.genefinder.Controller.prototype.setSelectionIndex"</span>;
    var badIndex = false;
    try {
        flyui.debug(<span class="literal">"setSelectionIndex, index: "</span>+index, _context);
        var results = <span class="reserved">this</span>._model.get(<span class="literal">"RESULTS"</span>);
        <span class="reserved">if</span> (results != null) {
            <span class="reserved">if</span> (index &gt;= 0 &amp;&amp; index &lt; results.length) {
                <span class="reserved">this</span>._model.set(<span class="literal">"SELECTIONINDEX"</span>, index);
    <span class="comment">//          flyui.debug("widget: "+this._parent, _context);</span>
                var event = <span class="reserved">this</span>._parent._geneSelectedEvent;
    <span class="comment">//          flyui.debug("event: "+event, _context);</span>
                event.fire(results[index]);
            }
            <span class="reserved">else</span> {
                badIndex = true;
            }
        }
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
    
    <span class="reserved">if</span> (badIndex) {
        throw new flyui.genefinder.SelectionOutOfBounds(<span class="literal">"index "</span>+index+<span class="literal">" cannot apply to results length "</span>+results.length);
    } 
};


<span class="comment">/**
 * <span class="attrib">@class</span>
 * An exception thrown if selection index is out of bounds.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {String} message
 */</span>
flyui.genefinder.SelectionOutOfBounds = <span class="reserved">function</span>( message ) {
	<span class="reserved">this</span>.name = <span class="literal">"flyui.genefinder.SelectionOutOfBounds"</span>;
	<span class="reserved">this</span>.message = message;
}


<span class="comment">/** 
 * Create a new renderer instance.
 * <span class="attrib">@class</span>
 * A default renderer for the GeneFinder Widget.
 */</span>
flyui.genefinder.DefaultRenderer = <span class="reserved">function</span>() {};

<span class="comment">/** 
 * <span class="attrib">@private</span> 
 * <span class="attrib">@type</span> Element
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._canvas = null;

<span class="comment">/**
 * <span class="attrib">@private</span> 
 * <span class="attrib">@type</span> Element
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._pendingPane = null;

<span class="comment">/**
 * <span class="attrib">@private</span> 
 * <span class="attrib">@type</span> Element
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._resultsSummaryPane = null;

<span class="comment">/**
 * <span class="attrib">@private</span> 
 * <span class="attrib">@type</span> Element
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._resultsPane = null;

<span class="comment">/**
 * <span class="attrib">@private</span> 
 * <span class="attrib">@type</span> Element
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._messagePane = null;

<span class="comment">/**
 * <span class="attrib">@private</span>
 * <span class="attrib">@type</span> flyui.genefinder.UserEventHandler
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._userEventHandler = null;

	
<span class="comment">/**
 * Set the DOM element to which this renderer applies and initialise it.
 * <span class="attrib">@param</span> {Element} canvas
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>.setCanvas = <span class="reserved">function</span>( canvas ) {
	<span class="reserved">this</span>._canvas = canvas;
	<span class="reserved">this</span>._initCanvas();
};


<span class="comment">/**
 * Set the user event handler.
 * <span class="attrib">@param</span> flyui.genefinder.UserEventHandler handler
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>.setUserEventHandler = <span class="reserved">function</span>( handler ) {
	<span class="reserved">this</span>._userEventHandler = handler;
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Initialise the main components of the widget's DOM
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._initCanvas = <span class="reserved">function</span>() {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype._initCanvas"</span>;
    try {
        
        YAHOO.util.Dom.addClass(<span class="reserved">this</span>._canvas, <span class="literal">"genefinderWidget"</span>);
    
        flyui.debug(<span class="literal">"setup pending pane"</span>, _context);
        <span class="reserved">this</span>._pendingPane = document.createElement(<span class="literal">"p"</span>);
        <span class="reserved">this</span>._pendingPane.innerHTML = <span class="literal">"pending..."</span>;
        <span class="reserved">this</span>._canvas.appendChild(<span class="reserved">this</span>._pendingPane);
        YAHOO.util.Dom.addClass(<span class="reserved">this</span>._pendingPane, <span class="literal">"pendingPane"</span>);
        flyui.mvcutils.hide(<span class="reserved">this</span>._pendingPane);
    
        flyui.debug(<span class="literal">"setup results summary pane"</span>, _context);
        <span class="reserved">this</span>._resultsSummaryPane = document.createElement(<span class="literal">"p"</span>);
        <span class="reserved">this</span>._resultsSummaryPane.innerHTML = <span class="literal">"this should never be displayed"</span>;
        <span class="reserved">this</span>._canvas.appendChild(<span class="reserved">this</span>._resultsSummaryPane);
        YAHOO.util.Dom.addClass(<span class="reserved">this</span>._resultsSummaryPane, <span class="literal">"resultsSummaryPane"</span>);
        flyui.mvcutils.hide(<span class="reserved">this</span>._resultsSummaryPane);
        
        flyui.debug(<span class="literal">"setup results pane"</span>, _context);
        <span class="reserved">this</span>._resultsPane = document.createElement(<span class="literal">"div"</span>);
        <span class="reserved">this</span>._canvas.appendChild(<span class="reserved">this</span>._resultsPane);
        YAHOO.util.Dom.addClass(<span class="reserved">this</span>._resultsPane, <span class="literal">"resultsPane"</span>);
        flyui.mvcutils.hide(<span class="reserved">this</span>._resultsPane);
    
        flyui.debug(<span class="literal">"message pane"</span>, _context);
        <span class="reserved">this</span>._messagePane = document.createElement(<span class="literal">"p"</span>);
        <span class="reserved">this</span>._messagePane.innerHTML = <span class="literal">"this should never be displayed"</span>;
        <span class="reserved">this</span>._canvas.appendChild(<span class="reserved">this</span>._messagePane);
        YAHOO.util.Dom.addClass(<span class="reserved">this</span>._messagePane, <span class="literal">"messagePane"</span>);
        flyui.mvcutils.hide(<span class="reserved">this</span>._messagePane); 

    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Called on widget model state changed.
 * <span class="attrib">@param</span> {String} from the old state
 * <span class="attrib">@param</span> {String} to the new state
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._onStateChanged = <span class="reserved">function</span>( from, to ) {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype._onStateChanged"</span>;
    try {
        <span class="reserved">if</span> ( to == <span class="literal">"PENDING"</span> ) {
            flyui.mvcutils.show(<span class="reserved">this</span>._pendingPane);
            flyui.mvcutils.hide(<span class="reserved">this</span>._messagePane);
            flyui.mvcutils.hide(<span class="reserved">this</span>._resultsSummaryPane);
            flyui.mvcutils.hide(<span class="reserved">this</span>._resultsPane);
        }
        <span class="reserved">else</span> <span class="reserved">if</span> ( to == <span class="literal">"READY"</span> ) {
            flyui.mvcutils.hide(<span class="reserved">this</span>._pendingPane);
            flyui.mvcutils.show(<span class="reserved">this</span>._messagePane);
            flyui.mvcutils.show(<span class="reserved">this</span>._resultsSummaryPane);
            flyui.mvcutils.show(<span class="reserved">this</span>._resultsPane);         
        } 
        <span class="reserved">else</span> <span class="reserved">if</span> ( to == <span class="literal">"SERVERERROR"</span> || to == <span class="literal">"UNEXPECTEDERROR"</span> ) {
            flyui.mvcutils.hide(<span class="reserved">this</span>._pendingPane);
            flyui.mvcutils.show(<span class="reserved">this</span>._messagePane);
            flyui.mvcutils.hide(<span class="reserved">this</span>._resultsSummaryPane);
            flyui.mvcutils.hide(<span class="reserved">this</span>._resultsPane);         
        } 
        <span class="reserved">else</span> {
            <span class="comment">// this should never happen</span>
            throw {message:<span class="literal">"unexpected state: "</span>+to};
        }
        
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   

};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Called on widget model query changed.
 * <span class="attrib">@param</span> {String} from the old query
 * <span class="attrib">@param</span> {String} to the new query
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._onQueryChanged = <span class="reserved">function</span>( from, to ) {
	<span class="comment">// temporarily store the query, do nothing else</span>
	<span class="reserved">this</span>._query = to;
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Called on widget model results changed.
 * <span class="attrib">@param</span> {Array&lt;flyui.flybase.Gene&gt;} from the old results
 * <span class="attrib">@param</span> {Array&lt;flyui.flybase.Gene&gt;} to the new results
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._onResultsChanged = <span class="reserved">function</span>( from, to ) {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype._onResultsChanged"</span>;
    try {
        <span class="comment">// temporarily store the results</span>
        <span class="reserved">this</span>._results = to;
        
        <span class="comment">// set the results summary</span>
        <span class="reserved">this</span>._renderResultsSummary(<span class="reserved">this</span>._query, to.length);
        
        <span class="reserved">if</span> (to.length &gt; 0) {
            
            <span class="comment">// empty the results pane</span>
            <span class="reserved">this</span>._resultsPane.innerHTML = <span class="literal">""</span>;   
    
            <span class="comment">// set the content</span>
            var resultsNode = <span class="reserved">this</span>._renderResults(to);
            flyui.debug(<span class="literal">"results node content:"</span>+resultsNode.innerHTML, _context);
            <span class="reserved">this</span>._resultsPane.appendChild(resultsNode); 
            
            <span class="comment">// set the message pane content</span>
            <span class="reserved">this</span>._renderGeneSelectionMessage(null);
    
        }
        <span class="reserved">else</span> {
            <span class="reserved">this</span>._resultsPane.innerHTML = <span class="literal">""</span>;
            <span class="reserved">this</span>._messagePane.innerHTML = <span class="literal">""</span>;
        }
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Called on model selection index changed
 * <span class="attrib">@param</span> {Number} from the old selection index
 * <span class="attrib">@param</span> {Number} to the new selection index
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._onSelectionIndexChanged = <span class="reserved">function</span>( from, to ) {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype._onSelectionIndexChanged"</span>;
    try {
        
        flyui.debug(<span class="literal">"from:"</span>+from+<span class="literal">", to:"</span>+to, _context);
        
        <span class="comment">// get the result nodes</span>
        var nodes = <span class="reserved">this</span>._getResultNodes(); <span class="comment">// that._resultsPane.getElementsByTagName("tr");</span>
        
        <span class="reserved">if</span> (from != null) {
            <span class="comment">// remove class</span>
            YAHOO.util.Dom.removeClass(nodes[from+1], <span class="literal">"selected"</span>);
        }
        
        <span class="reserved">if</span> (to != null) {
            <span class="comment">// add class</span>
            flyui.info(<span class="literal">"adding selected class to node: "</span>+nodes[to+1]+<span class="literal">"debug"</span>, _context);
            YAHOO.util.Dom.addClass(nodes[to+1], <span class="literal">"selected"</span>);
            var gene = <span class="reserved">this</span>._results[to];
            <span class="reserved">this</span>._renderGeneSelectionMessage(gene);
        }   
        
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Utility function to access result DOM elements.
 * <span class="attrib">@type</span> Array&lt;Element&gt;
 * <span class="attrib">@return</span> an array of elements
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._getResultNodes = <span class="reserved">function</span>() {
	<span class="reserved">return</span> <span class="reserved">this</span>._resultsPane.getElementsByTagName(<span class="literal">"tr"</span>);
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Called on error message changed
 * <span class="attrib">@param</span> {String} from the old message
 * <span class="attrib">@param</span> {String} to the new message
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._onErrorMessageChanged = <span class="reserved">function</span>( from, to ) {
	<span class="reserved">this</span>._messagePane.innerHTML = to;
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Main callback function for model changes.
 * <span class="attrib">@param</span> {String} type the name of the model property changed
 * <span class="attrib">@param</span> {Array} args the callback args
 * <span class="attrib">@param</span> {flyui.genefinder.DefaultRenderer} self a self reference, to work around callback issues
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._onModelChanged = <span class="reserved">function</span>(type, args, self) {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype._onModelChanged"</span>;
    try {
        var handlers = {
            <span class="literal">"STATE"</span>:<span class="literal">"_onStateChanged"</span>,
            <span class="literal">"QUERY"</span>:<span class="literal">"_onQueryChanged"</span>,
            <span class="literal">"RESULTS"</span>:<span class="literal">"_onResultsChanged"</span>,
            <span class="literal">"ERRORMESSAGE"</span>:<span class="literal">"_onErrorMessageChanged"</span>,
            <span class="literal">"SELECTIONINDEX"</span>:<span class="literal">"_onSelectionIndexChanged"</span>
        };
        var handler = handlers[type];
        <span class="comment">// call the handler</span>
        self[handler](args[0], args[1]);
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
};


<span class="comment">/**
 * Connect this renderer to a model.
 * <span class="attrib">@param</span> {flyui.mvcutils.GenericModel2} model
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>.connect = <span class="reserved">function</span>( model ) {
	var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype.connect"</span>;
	try {
        model.subscribeAll(<span class="reserved">this</span>._onModelChanged, <span class="reserved">this</span>);
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
};


<span class="comment">/**
 * Helper function for building DOM elements containing lists of elements
 * <span class="attrib">@param</span> {string} outerTag outer tag (e.g. "TR") 
 * <span class="attrib">@param</span> {string} innerTag inner tag (e.g. "TD") 
 * <span class="attrib">@param</span> {string*} list of inner HTML values to populate element
 * <span class="attrib">@return</span> a new DOM element constructed from supplied values
 * <span class="attrib">@type</span> HTMLElement 
 */</span>
flyui.genefinder.DefaultRenderer.renderDomElementFromList = <span class="reserved">function</span>(outerTag, innerTag, list) {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.renderDomElementFromList"</span>;
    try {
        var outerElem = document.createElement(outerTag);
    
        <span class="comment">// can we defer this to caller?  tbody.appendChild(headerRow);</span>
        
        flyui.debug(<span class="literal">"creating outer "</span>+outerTag, _context);
        <span class="reserved">for</span> (var i=0; i&lt;list.length; i++) {
            var innerElem = document.createElement(innerTag);
            innerElem.innerHTML = list[i];
            outerElem.appendChild(innerElem);
        }   
    
        <span class="reserved">return</span> outerElem;   
        
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Render the results summary pane.
 * <span class="attrib">@param</span> {String} query the user's query
 * <span class="attrib">@param</span> {Number} count number of results found
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._renderResultsSummary = <span class="reserved">function</span>( query, count ) {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype._renderResultsSummary"</span>;
    try {
        var content = <span class="literal">"showing "</span>;
        content += count;
        content += <span class="literal">" matching gene"</span>;
        content += (count == 0 || count &gt; 1) ? <span class="literal">"s "</span> : <span class="literal">" "</span>;
        content += <span class="literal">"from &lt;a href='http://www.flybase.org'&gt;www.flybase.org&lt;/a&gt; for query '"</span>+query+<span class="literal">"'..."</span>;
        <span class="reserved">this</span>._resultsSummaryPane.innerHTML = content;
        
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
}


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Render the results pane.
 * <span class="attrib">@param</span> {Array&lt;flyui.flybase.Gene&gt;} genes the results of the user's query
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._renderResults = <span class="reserved">function</span>( genes ) {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype._renderResults"</span>;
    try {
        <span class="comment">// set up overall table structure</span>
        var table = document.createElement(<span class="literal">"table"</span>);
        var thead = document.createElement(<span class="literal">"thead"</span>);
        var tbody = document.createElement(<span class="literal">"tbody"</span>);
        table.appendChild(thead);
        table.appendChild(tbody);
    
        <span class="comment">// set up header row</span>
        var headers = [<span class="literal">"symbol"</span>, <span class="literal">"full name"</span>, <span class="literal">"annotation ID"</span>, <span class="literal">"flybase ID"</span>, <span class="literal">"user selection"</span>];
        var headerRow = flyui.genefinder.DefaultRenderer.renderDomElementFromList(<span class="literal">"tr"</span>, <span class="literal">"th"</span>, headers); 
        thead.appendChild(headerRow);
        
        <span class="reserved">for</span> (var i=0; i&lt;genes.length; i++) {
            flyui.debug(<span class="literal">"creating result row "</span>+i, _context);
            var cellContents = <span class="reserved">this</span>._geneToTableCellContents(genes[i]);
            var row = flyui.genefinder.DefaultRenderer.renderDomElementFromList(<span class="literal">"tr"</span>, <span class="literal">"td"</span>, cellContents);
            tbody.appendChild(row);
            YAHOO.util.Event.addListener(row, <span class="literal">"click"</span>, <span class="reserved">this</span>._userEventHandler._onResultClicked, i);
        }
        
        <span class="reserved">return</span> table;
        
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
	
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Utility function to turn a gene into an array of table cell contents.
 * <span class="attrib">@param</span> {flyui.flybase.Gene} gene
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._geneToTableCellContents = <span class="reserved">function</span>( gene ) {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype._geneToTableCellContents"</span>;
    try {
        <span class="reserved">return</span> [
            gene.symbols.join(<span class="literal">" / "</span>),
            gene.fullNames.join(<span class="literal">" / "</span>),
            gene.annotationSymbols.join(<span class="literal">" / "</span>),
            gene.flybaseID,
            <span class="literal">"&lt;span class='selector'&gt;[&lt;a href='javascript:void(0)'&gt;select this gene&lt;/a&gt;]&lt;/span&gt;&lt;span class='isselected'&gt;selected&lt;/span&gt;"</span>
        ];
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
}


<span class="comment">/**
 * <span class="attrib">@private</span>
 * Render a message for the given selection.
 * <span class="attrib">@param</span> {flyui.flybase.Gene} gene the selected gene (may be null for no selection)
 */</span>
flyui.genefinder.DefaultRenderer.<span class="reserved">prototype</span>._renderGeneSelectionMessage = <span class="reserved">function</span>( gene ) {
    var _context = <span class="literal">"flyui.genefinder.DefaultRenderer.prototype._renderGeneSelectionMessage"</span>;
    try {
        
        <span class="reserved">if</span> (gene == null) {
            <span class="reserved">this</span>._messagePane.innerHTML = <span class="literal">"selected gene: &lt;strong&gt;please select one of the genes from the list above, or try another query&lt;/strong&gt;"</span>;
        }
        <span class="reserved">else</span> {
            <span class="reserved">this</span>._messagePane.innerHTML = <span class="literal">"selected gene: &lt;strong&gt;"</span>+gene.symbols.join(<span class="literal">" / "</span>)+<span class="literal">"&lt;/strong&gt; ("</span>+gene.flybaseID+<span class="literal">") [&lt;a href='http://flybase.org/reports/"</span>+gene.flybaseID+<span class="literal">".html'&gt;FlyBase gene report&lt;/a&gt;]"</span>;
        }  
              
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name, <span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }   
};


<span class="comment">/** 
 * Definition of genefinder widget model.
 */</span>
flyui.genefinder.modelDefinition = {

	properties : [ <span class="literal">"STATE"</span>, <span class="literal">"RESULTS"</span>, <span class="literal">"ERRORMESSAGE"</span>, <span class="literal">"QUERY"</span>, <span class="literal">"SELECTIONINDEX"</span> ],
	
	values : {
		<span class="literal">"STATE"</span> : [ <span class="literal">"READY"</span>, <span class="literal">"PENDING"</span>, <span class="literal">"SERVERERROR"</span>, <span class="literal">"UNEXPECTEDERROR"</span> ]
	},
	
	initialize : <span class="reserved">function</span>( data ) {
		data[<span class="literal">"STATE"</span>] = <span class="literal">"READY"</span>;
		data[<span class="literal">"RESULTS"</span>] = null;
		data[<span class="literal">"ERRORMESSAGE"</span>] = null;
		data[<span class="literal">"QUERY"</span>] = null;
		data[<span class="literal">"SELECTIONINDEX"</span>] = null;
	}
}</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Tue Dec  9 11:08:18 2008</div>
</body>
</html>
